
const cloud = require('wx-server-sdk')
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV })

exports.main = async (event, context) => {
  const db = cloud.database()
  try {
    const res = await db.collection('accountBook')
      .where({ _openid: cloud.getWXContext().OPENID })
      .field({ _id: 1, type: 1, name: 1, records: 1 })
      .get()
    return { code: 200, data: res.data }
  } catch (err) {
    return { code: 500, msg: '数据库查询失败' }
  }
}